import TUIChatEngine from "@tencentcloud/chat-uikit-engine";
import { genTestUserSig } from "./debug";
import Server from "./server";
import TUIComponents, {
  TUIChat,
  TUIConversation,
  TUIContact,
  TUISearch,
  TUIGroup,
} from "./components";

import { StoreName, TUIStore, TUITranslateService } from '@tencentcloud/chat-uikit-engine';
import {locales} from "/@/locales";
import TUINotification from "/@/TUIKit/components/TUINotification";

const TUIChatKit = new Server();


TUITranslateService.provideLanguages(locales);
TUITranslateService.useI18n();

/**
 * Init TUINotification configuration.
 */
TUINotification.setNotificationConfiguration({
  showPreviews: true,
  allowNotifications: true,
  notificationTitle: 'Tencent Cloud Chat',
  notificationIcon: 'https://web.sdk.qcloud.com/im/demo/latest/faviconnew.png',
});

/**
 * Listen for new messages and use notification components.
 * This capability is only available in the web environmen.
 */
TUIStore.watch(StoreName.CHAT, {
  newMessageList: (newMessageList: unknown) => {
    if (Array.isArray(newMessageList)) {
      newMessageList.forEach((message) => TUINotification.notify(message));
    }
  },
});


export {
  TUIChatKit,
  TUIChatEngine,
  TUIComponents,
  TUIChat,
  TUIConversation,
  TUIContact,
  TUISearch,
  TUIGroup,
  genTestUserSig,
};
